package com.gip.controller;

import com.gip.mapper.DataMapper;
import com.gip.mapper.OrderMapper;
import com.gip.pojo.Record;
import com.gip.service.CustomerService;
import com.gip.service.OrderService;
import com.gip.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class MenuController {
    @Autowired
    UserService userService;
    @Autowired
    DataMapper dataMapper;
    @Autowired
    OrderService orderService;
    @Autowired
    CustomerService customerService;
    @Autowired
    OrderMapper orderMapper;
    @RequestMapping("goTable1")
    public String goTable() {
        return "table";
    }

    @RequestMapping("goTable2")
    public String goTable2() {
        return "table2";
    }

    @RequestMapping("orderTable")
    public String orderTable() {
        return "orderTable";
    }

    @RequestMapping("customerTable")
    public String customerTable(Model model) {
        List<String> allMajor = dataMapper.findAllMajor();
        model.addAttribute("allMajor", allMajor);
        return "customerTable";
    }
    @RequestMapping("/welcome")
    public String welcome(Model model){
        int i = userService.conutUser();
        model.addAttribute("userCount",i);
        int j = orderService.countOrders();
        model.addAttribute("orderCount",j);
        int k = customerService.countCustomer();
        model.addAttribute("customerCount",k);
        return "welcome";
    }
    @RequestMapping("/404")
    public String noFound(){
        return "404";
    }
    @RequestMapping("/tip")
    public String tip(Model model){
        List<Record> outRecord = orderMapper.findOutRecord();
        if(outRecord!=null){
            model.addAttribute("outRecord",outRecord);
        }
        return "tip";
    }
}
